<?php
require_once('db/db.php');
$db=new DB;

$data=$db->get_all('select `id`,`desc` from category where father=0');
array_unshift($data, array('id'=>0, 'desc'=>'顶级类别'));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="keywords" content="jquery,ui,easy,easyui,web">
	<meta name="description" content="easyui help you build your web page easily!">
	<title>产品分类管理</title>
    
    <link rel="stylesheet" type="text/css" href="js/themes/default/easyui.css">  
    <link rel="stylesheet" type="text/css" href="js/themes/icon.css">  
    <link rel="stylesheet" type="text/css" href="js/admin.css">
    
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="js/jz.js"></script>
	<script type="text/javascript">
		$(function(){
			$('#dg').edatagrid({
				url: 'get_ca.php',
				saveUrl: 'save_ca.php',
				updateUrl: 'update_ca.php',
				destroyUrl: 'destroy_ca.php',
				/*onBeforeSave: function(index){
					var value=$('#gd .combo-value').attr('value');
					if(value==index){alert('上级分类不能选择自己');}
					return false;
				}*/
			});
		});
		var all_ca= <?php echo json_encode($data); ?>;
		function ca_formatter(value,row,index){
			var text='';
			for(var i=0; i< all_ca.length; i++){
				if(all_ca[i].id==value) {
					text=all_ca[i].desc;
					break;
				}
			}
			return text;
		}
	</script>
</head>
<body>
	<h2>产品分类管理</h2>
	
	<table id="dg" title="推广活动" style="width:700px;height:750px"
			toolbar="#toolbar" pagination="true" idField="id"
			rownumbers="true" fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<th field="father" width="30" formatter="ca_formatter" editor="{type:'combobox',options:{
								valueField:'id',
								textField:'desc', 
								panelHeight:'80',
								url:'getallfatherca.php', 
                                required:true}}">上级类别</th>
				<th field="desc" width="70" editor="{type:'validatebox',options:{required:true}}">类别名称</th>
			</tr>
		</thead>
	</table>
	<div id="toolbar">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$('#dg').edatagrid('addRow')">增加</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:$('#dg').edatagrid('destroyRow')">删除</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:$('#dg').edatagrid('saveRow')">保存</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="javascript:$('#dg').edatagrid('cancelRow')">取消</a>
	</div>
	
</body>
</html>
